<%@page import="com.eos.common.tool.ConstantTool"%>
<%@page import="com.eos.orm.mybatis.model.ProductModel"%>
<%@page import="com.eos.orm.mybatis.model.SysProduct"%>
<%@page import="com.eos.orm.mybatis.model.ProductBrand"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html; charset=utf-8"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
List<ProductBrand> brandList = (List<ProductBrand>)request.getAttribute("brandList");
List<SysProduct> productList = (List<SysProduct>) request.getAttribute("productList");
List<ProductModel> modelList = (List<ProductModel>) request.getAttribute("modelList");
%>
<style>
.page .searchBar label{width: 40px;}
</style>
<script type="text/javascript">
	$(document).ready(function(){
		$("#proId").change(function(){
			var $this = $(this);
			if($this.val()== ""){
				$("#brId option").not(":first").remove();
			}else{
				var txt = $("#span_proBrandJson").text(), proId = $this.val();
				if($.trim(txt) != ""){
					$("#brId option").not(":first").remove();
					var selJson = $.parseJSON(txt);
					$.each(selJson, function(i){
						var key2 = 'pro_'+proId;
						if(i == key2){ 
							$.each(selJson[i], function(j){
								$("#brId").append('<option value="'+selJson[i][j].id+'">'+selJson[i][j].brandName+'</option>');
							});
						}
					});
				}
			}
		});
		
		initPro2(); 
	});
	
	function initPro2(){
		var txt = $("#span_proBrandJson").text(), mProId = $("#hPrId").val(), mBrandId = $("#hBrId").val(); 
		if($.trim(txt) != ""){
			$("#brId option").not(":first").remove();
			var selJson = $.parseJSON(txt), sel='';
			$.each(selJson, function(i){
				var key2 = 'pro_'+mProId;
				if(i == key2){ 
					$.each(selJson[i], function(j){
						if(mBrandId==selJson[i][j].id){sel= ' selected="selected" ';}
						$("#brId").append('<option'+ sel+' value="'+selJson[i][j].id+'">'+selJson[i][j].brandName+'</option>');
						sel = '';
					});
				}
			});
		}
	}
</script>
<!-- 此处加action="employeeCtrl.ctrl"是为了条件查询时仍能显示排序图标 -->
<form id="pagerForm" method="post" action="categoryList">
	<input type="hidden" name="pageNum" value="${pageNum}" />
	<input type="hidden" name="numPerPage" value="${numPerPage}" />
</form>
<div class="pageHeader">
	<form onsubmit="return navTabSearch(this);" rel="pagerForm" method="post" action="categoryList">
		<div class="searchBar">
			<input type="hidden" name="numPerPage" value="${numPerPage}" />
			<input type="hidden" name="pageNum" value="${pageNum}" /> 
			<table class="searchContent">
				<tr>
					<td>
						<label style="width:60px;">型号名称:</label>
						<input type="text" name="modelName"  value="${modelName }" />
					</td>
					<td>
						<label>品 名：</label>
						<select name="productId" id="proId">
							<option value="">-选择品名-</option>
							<c:forEach var="pro" items="${productList }">
								<option value="${pro.id }" ${pro.id==productId ? "selected='selected'" : "" }>${pro.productName }</option>
							</c:forEach>
						</select>
					</td>
					<td>
						<label>品 牌： </label>
						<select name="brandId" id="brId">
							<option value="">-选择品牌-</option>
						</select>
					</td>
					<td>
						<label>状 态： </label>
						<select name="dealFlag">
							<option value="" ${dealFlag=="" ? "selected='selected'" : ""}>全部</option>
							<option value="0" ${dealFlag=="0" ? "selected='selected'" : ""}>正常</option>
							<option value="1" ${dealFlag=="1" ? "selected='selected'" : ""}>删除</option>
						</select>
					</td>
					<td>
						<div class="subBar">
							<ul>
								<li>
									<div class="buttonActive">
										<div class="buttonContent">
											<button type="submit">
												检索
											</button>
										</div>
									</div>
								</li>
							</ul>
						</div>
					</td>
				</tr>
			</table>
		</div>
	</form>
</div>
<div class="pageContent">
	<div class="panelBar">
		<ul class="toolBar">
			<li>
				<a class="add" style="font-weight: bold;color:#4BBB13;" href="addCategory?navTabId=addCategory" width="435" height="300" target="dialog" mask="true" maxable="false" title="新增产品型号"><span>新 增</span>
				</a>
			</li>
			<li class="line">line</li>
			<li>
				<a class="edit" style="font-weight: bold;color:#6495ED;" href="editCategory?modelId={sid_modelId}&navTabId=editCategory"
					 target="dialog" mask="true" maxable="false" width="435" height="300"  rel="editCategory" title="编辑产品型号信息"><span>编 辑</span>
				</a>
			</li>
			<li class="line">line</li>
			<li>
				<a class="delete" style="font-weight: bold;color:#C1272A;" href="delCategory?modelId={sid_modelId}"
					target="ajaxTodo" title="确定要删除您所选中的产品型号吗?"><span>删 除</span>
				</a>
				<span style="display: none;" id="span_proBrandJson">${brandOfProductJson }</span>
				<input type="hidden" value="${productId }" id="hPrId" />
				<input type="hidden" value="${brandId }" id="hBrId" />
			</li>
		</ul>
	</div>
	<table class="table" width="100%" layoutH="115">
		<thead>
			<tr>
				<th wdith="80">序号</th>
				<th>型号ID</th>
				<th>品名</th>
				<th>品牌名称</th>
				<th>型号名称</th>
				<th>创建时间</th>
				<th>修改时间</th>
				<th>配置</th>
				<th>状态</th>
			</tr>
		</thead>
		<tbody>
			 <% 
			 	if(null != modelList){
			 	int i = 1;
			 	for(ProductModel m : modelList){
			 %>
			 	<tr target="sid_modelId" rel="<%=m.getId() %>">
					<td><%=i++ %></td>
					<td><%=m.getId() %></td>
					<td>
						<%for(SysProduct pro : productList){ 
							if(pro.getId() == m.getProductId()){
								out.print(pro.getProductName());
								break;
							}
						} %>
					</td>
					<td>
					<%
					 for(ProductBrand br : brandList){
					 	if(br.getId() == m.getBrandId()){
					 		out.print(br.getBrandName());
					 		break;
					 	}
					 }
					 %>
					</td>
					<td><%=m.getModelName() %></td>
					<td><%=m.getInsertTime() %></td>
					<td><%=m.getModifyTime() %></td>
					<td><%=m.getModelDesc() == null ? "" : m.getModelDesc() %></td>
					<td style="color:#006400;">
					<%if(m.getDealFlag().equals(ConstantTool.DEAL_FALG_OK)){%>
						<a style="text-decoration: none;color:#006400;">正常</a>
					<%}else{ %>
						<a style="text-decoration: none;color:#f00;">删除</a>
					<%} %>
					</td>
				</tr>
			 <%}
			 
			 } %>
		</tbody>
	</table>
	<div class="panelBar">
		<div class="pages">
			<span>显示</span>
			<!-- pageNum:1是当更改numPerPage时，使pageNum=1重新开始，否则可能无数据 -->
			<select class="combox" name="numPerPage"
				onchange="navTabPageBreak({numPerPage:this.value, pageNum:1})">
				<option value="15" ${numPerPage==15?'selected':''}>
					15
				</option>
				<option value="20" ${numPerPage==20?'selected':''}>
					20
				</option>
				<option value="25" ${numPerPage==25?'selected':''}>
					25
				</option>
				<option value="50" ${numPerPage==50?'selected':''}>
					50
				</option>
				<option value="100" ${numPerPage==100?'selected':''}>
					100
				</option>
			</select>
			<span>条，共${totalCount }条 </span>
		</div>
		<div class="pagination" targetType="navTab" totalCount="${totalCount }" numPerPage="${numPerPage}" pageNumShown="5" currentPage="${pageNum }"></div>
	</div>
</div>
